﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using System.Data.SqlClient;
using System.Xml.Serialization;
using System.ComponentModel;

namespace XEvents.Library
{
    [Serializable]
    public class Target : XEObjectBase
    {
        internal Target(dm_xe_object obj, SqlServer server)
            : base(obj, server)
        { }

        private Target()
            : base(null)
        { }

        public override bool Equals(object obj)
        {
            if (obj == null) return false;

            if (this.GetType() != obj.GetType()) return false;

            // safe because of the GetType check
            Target tgt = (Target)obj;

            // use this pattern to compare reference members
            if (!Object.Equals(Name, tgt.Name)) return false;
            if (!Package.Equals(Package, tgt.Package)) return false;

            return true;
        } 

        [BrowsableAttribute(false), ReadOnlyAttribute(true)]
        public ColumnCollection Fields
        {
            get
            {
                return new ColumnCollection(from c in Server.MetaData.object_columns
                       where c.object_name == this.name
                       && c.object_package_guid == this.package_guid
                       && c.column_type != "readonly"
                       // TODO:  add additional filtering here....
                       select new Column(c, this.Server));
            }
        }
        

        /// <summary>
        /// Capabilities
        /// </summary>
        [XmlAttribute("Capabilities"), ReadOnlyAttribute(true)]
        public int Capabilities
        {
            get
            {
                return capabilities;
            }
        }

        /// <summary>
        /// CapabilitiesDescription
        /// </summary>
        [XmlAttribute("CapabilitiesDescription"), ReadOnlyAttribute(true)]
        public string CapabilitiesDescription
        {
            get
            {
                return capabilities_desc;
            }
        }
    }
}
